import 'dart:io';
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';

class FileUtil {
  static Future<Directory> getPath() async {
    Map<PermissionGroup, PermissionStatus> permissions =
        await PermissionHandler().requestPermissions([PermissionGroup.storage]);
    if (permissions[PermissionGroup.storage] == PermissionStatus.granted) {
      Directory directory = Platform.isAndroid
          ? await getExternalStorageDirectory()
          : await getApplicationDocumentsDirectory();
      return directory;
    } else {
      return null;
    }
  }

  static bool deleteFile(String path) {
    try {
      File file = File(path);
      if (file.existsSync()) {
        file.deleteSync();
      }
      return true;
    } catch (ex) {
      print(ex);
      return null;
    }
  }
}
